package com.jiangli.controller.user;

import com.jiangli.annotation.RateLimit;
import com.jiangli.dto.MerchantRatingDTO;
import com.jiangli.entity.Merchant;
import com.jiangli.entity.MerchantRating;
import com.jiangli.result.PageResult;
import com.jiangli.result.Result;
import com.jiangli.service.MerchantService;
import com.jiangli.vo.MerchantDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiangli.vo.MerchantRaingVO;
@RestController
@RequestMapping("/user/merchant")
@Slf4j
@Api(tags = "用户-有关商家接口")
public class MerchantController {


    @Autowired
    private MerchantService merchantService;
    @RateLimit
    @PostMapping("/rate")
    @ApiOperation("用户对商家评分")
    public Result rating(@RequestBody MerchantRatingDTO merchantRatingDTO) {
        log.info("对商家评分{}", merchantRatingDTO);
        merchantService.addRate(merchantRatingDTO);
        return Result.success();
    }
    @RateLimit
    @GetMapping("/rate")
    @ApiOperation("获取用户对商家的评分")
    public Result<MerchantRaingVO>getRating(@RequestParam Long userId,@RequestParam Long merchantId){
       MerchantRaingVO merchantRatingVO= merchantService.getUserMerchantRating(userId,merchantId);
       return Result.success(merchantRatingVO);
    }
    @RateLimit
    @GetMapping("/rank")
    @ApiOperation("商家排名")
    public Result<PageResult> showMerchantRank(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "false") boolean reset
    ){
        return Result.success(merchantService.showMerchantRank(page, pageSize,reset));
    }
    @RateLimit
    @GetMapping("/recommend")
    @ApiOperation("推荐商家")
    public Result<PageResult> recommend(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "false") boolean reset
    ){
        return Result.success(merchantService.getRecommendedMerchantByPage(page,pageSize,reset));
    }
    @RateLimit
    @GetMapping("/getDetail/{merchantId}")
    @ApiOperation("获取商家详情")
    public Result<MerchantDetailVO>getDetail(@PathVariable Long merchantId){
        MerchantDetailVO merchantDetailVO=merchantService.showDetail(merchantId);
        return Result.success(merchantDetailVO);
    }
}
